home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0027_OOP Keyboard Routines.pas < prev    next >
Pascal/Delphi Source File  |  1993-06-22  |  3KB  |  112 lines

  1. UNIT Keybd;  { Keybd.PAS / Keybd.TPU }
  2.  
  3. INTERFACE
  4.  
  5. USES Crt, Dos;
  6.  
  7. TYPE
  8.   CType = ( UBAR, BLOCK );
  9.   Keyboard = OBJECT
  10.     ThisCursor: CType;
  11.     PROCEDURE InitKeyBd;
  12.     PROCEDURE SetCursor( Cursor: CType );
  13.     FUNCTION  GetCursor: CType;
  14.     FUNCTION  GetKbdFlags: Byte;
  15.     FUNCTION  GetKey( VAR KeyFlags: Byte; VAR FunctKey: Boolean;
  16.                                         VAR Ch: Char ): Boolean;
  17.   END;
  18.  
  19. {***************************************************************}
  20.                       IMPLEMENTATION
  21. {***************************************************************}
  22.  
  23.  
  24. {Keyboard}
  25.  
  26. {-------------------------------------------------
  27. - Name   : InitKeyBd                             -
  28. - Purpose: Set the cursor to underline style     -
  29. -          and empty keyboard buffer             -
  30. -------------------------------------------------}
  31.  
  32. PROCEDURE Keyboard.InitKeyBd;
  33.   VAR
  34.     Ch : Char;
  35.   BEGIN
  36.     SetCursor( UBAR );
  37.     WHILE( KeyPressed ) DO Ch := ReadKey;
  38.   END;
  39.  
  40. {-------------------------------------------------
  41. - Name   : SetCursor                             -
  42. - Purpose: Modify number of lines for cursor     -
  43. -------------------------------------------------}
  44.  
  45. PROCEDURE Keyboard.SetCursor;
  46.   VAR
  47.     Regs: Registers;
  48.   BEGIN
  49.     CASE Cursor OF
  50.       UBAR:  Regs.Ch := 6;
  51.       BLOCK: Regs.Ch := 1;
  52.     END;
  53.     Regs.CL := 7;
  54.     Regs.AH := 1;
  55.     Intr( $10, Regs );
  56.   END;
  57.  
  58. {-------------------------------------------------
  59. - Name   : GetKbdFlags                           -
  60. - Purpose: Monitor the Insert key                -
  61. - Output : Shift key status flag byte            -
  62. -------------------------------------------------}
  63.  
  64. FUNCTION  Keyboard.GetKbdFlags: Byte;
  65.   VAR
  66.     Regs: Registers;
  67.   BEGIN
  68.     (* FOR enhanced keyboards: AH := $12 *)
  69.     (* FOR normal keyboards:   AH := $02 *)
  70.     Regs.AH := $12;
  71.     Intr( $16, Regs );
  72.     IF( Regs.AX AND $80 = $80 ) THEN SetCursor( BLOCK )
  73.                                 ELSE SetCursor( UBAR );
  74.     GetKbdFlags := Regs.AX;
  75.   END;
  76.  
  77. {-------------------------------------------------
  78. - Name   : GetCursor                             -
  79. - Purpose: Query current cursor state            -
  80. -------------------------------------------------}
  81.  
  82. FUNCTION  Keyboard.GetCursor;
  83.   BEGIN
  84.     GetCursor := ThisCursor;
  85.   END;
  86.  
  87. {-------------------------------------------------
  88. - Name   : GetKey                                -
  89. - Purpose: Get a keypress contents if any        -
  90. -          Updates a function keypressed flag    -
  91. -------------------------------------------------}
  92.  
  93. FUNCTION  Keyboard.GetKey;
  94.   VAR
  95.     Result : Boolean;
  96.   BEGIN
  97.     Result := KeyPressed;
  98.     FunctKey := FALSE;
  99.     Ch := #$00;       {Use this to check for Function key press}
  100.     IF Result THEN BEGIN
  101.       Ch := ReadKey;
  102.       IF( KeyPressed AND ( Ch = #$00 ) ) THEN BEGIN
  103.         Ch := ReadKey;
  104.         FunctKey := TRUE;
  105.         END;
  106.       END;
  107.     KeyFlags := GetKbdFlags;
  108.     GetKey := Result;
  109.     END;
  110.  
  111. END.
  112.